package com.zmj.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 全局拦截器配置
 *
 * @author zmj
 * @date 2021-08-30 10:44
 */

@Slf4j
public class CustomizeInterceptor implements HandlerInterceptor {

    /**
     * 请求方法前
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        if (requestURI.contains("interceptor")) {
            log.info("preHandle 拦截成功 请求路径是{}", requestURI);
            return false;
        }
        return true;
    }
    
    /**
     * 请求方法后
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    /**
     * 请求方法后,页面渲染前
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
